<template>
  <div>
      <page-header title="三方违约处理" content="tripartiteAdmin" />
      <page-main>
         <search-bar>
            <el-form :model="search" size="small" label-width="120px">
                <el-row> 
                    <el-col :span="8">
                        <el-form-item label="名称">
                            <el-input v-model="search.name" placeholder="请输入名称，支持模糊查询" clearable />
                        </el-form-item>
                    </el-col>
                    <el-col :span="2">
                        <el-form-item>
                            <el-button type="primary" icon="el-icon-search" @click="searchData()">筛选</el-button>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
        </search-bar>
      </page-main>
      <page-main v-loading="loading">
            <TableList 
              :tableKey="tableKey" 
              :dataList="searchList" 
              v-if="dataLists.length != 0" 
              entityKey='tripartite' 
              @tripartiteProcess="tripartiteProcess" 
              :process="true">
            </TableList>
      </page-main>
  </div>
</template>

<script>
export default {
    name: 'tripartiteAdmin',
    data() {
        return {
            search: {
                name: '',
            },
            dataLists: [],
            searchList: [],
            tableKey: [{
                name: 'id',
                value: 'id'
            },{
                name: 'stuname',
                value: '学生'
            },{
                name: 'filepath',
                value: '相关文件'
            },{
                name: 'timestamp1',
                value: '提交时间'
            }],
            type: {
                Chinese: '',
                English: ''
            },
            loading: true
        }
    },
    created() {
       this.loadAllTripartite()
    },
    methods: {
        tripartiteProcess(row) {
            this.$router.push('/tripartite/process/' + row.id)
        },
        loadAllTripartite() {
            this.$util.post('public/loadAllTripartite').then(res => {
                this.dataLists = []
                this.searchList = []
                for(let i = 0; i < res.length; i++) {
                  let obj = res[i]
                  this.$util.post('public/loadUserdetailByUid',{uid: obj.uid}).then(res => {
                    obj.stuname = res.nickname
                  })
                  if(!JSON.parse(res[i].abrogation)) {
                      this.dataLists.push(obj)
                      this.searchList.push(res[i])
                  }
                }
                setTimeout(() => {
                  this.loading = false
                }, 2000)
            })
        },
        searchData() {
            this.searchList = []
            if(this.search.name == '') {
                this.dataLists.forEach(item => {
                    this.searchList.push(item)
                })
            } else {
                this.dataLists.forEach((item) => {
                    if(item.stuname.indexOf(this.search.name) != -1) {
                        this.searchList.push(item)
                    }
                })
            }
        }
    }
}
</script>

